Learn how to track events for Personalization in the Algolia extension for Magento 2.
userToken
parameter for all events you track and for your search.
The extension automatically handles the generation of this token.
For first-time customers (not logged in) an anonymous userToken
is created by the Algolia search-insights library.
If a customer consents to using cookies on your site, the anonymous token is stored in the _ALGOLIA
cookie.
If consent isn’t granted, the token will be regenerated on every request:
this means you can’t track that user’s activity or provide them with personalized search results.
To retain personalization data across sessions, once a customer logs into their account, a unique 64-character authenticatedUserToken
is generated from Magento based on email address and customer ID.
However, to comply with data privacy laws, this information is one-way encrypted to avoid exposure of any Personally Identifiable Information (PII) in the underlying event data.
Algolia stores this token in a cookie named:
_ALGOLIA_MAGENTO_AUTH
from version 3.14.x
aa-search
for previous versions.3.14.x
, to correlate activities that a user performs before and after logging in, Algolia tracks the entire customer journey by sending both the anonymous token and authenticated token with events.
This ensures that activities performed before the login event are included when determining the customer’s shopping preferences.
The following table shows which tokens are used for the various scenarios that may occur during the customer journey:
userToken | authenticatedUserToken | |
---|---|---|
First time visitor | ||
Customer logs in | ||
Customer session expires | ||
Customer logs out |
authenicatedToken
and not rely solely on a potentially ephemeral anonymous token.userToken
also improves analytics accuracy by sending the Insights events token with queries.
However, because queries can only be associated with a single userToken
, once a customer has logged in to their account the authenticatedToken
is sent with all queries instead of the anonymous user token.
userToken
in cookies.
For information about how the Algolia extension determines consent, see cookie law compliance .
afterInsightsBindEvents
frontend event.
This hook exposes the algoliaInsights
object, which lets you append events to the list of pre-configured events.
There are three methods available in the algoliaInsights
object that you can use to add a new Personalization event:
trackClick
trackView
trackConversion
buildEventData
method on the algoliaInsights
object. To create a personalization event in the correct format, buildEventData
requires an eventName
, objectID
and indexName
.
The following code snippet shows how to add a custom click event using the afterInsightsBindEvents
hook: